#ifndef BRACES_H
#define BRACES_H
#include <stack>
#include <string>
// valid_braces函数使用栈判断括号是否匹配
bool valid_braces(std::string braces)
{
    std::stack<char> st;
    for (auto i : braces) {
        if (st.empty()) {
            st.push(i);
            continue;
        }
        char top = st.top();
        if ((top == '[' && i == ']') || (top == '(' && i == ')') || (top == '{' && i == '}')) {
            st.pop();
            continue;
        } else if ((top == '[' || top == '(' || top == '{') && (i == '[' || i == '(' || i == '{')) {
            st.push(i);
            continue;
        }
        return false;
    }
    return st.empty();
}
#endif